package myset;

import java.util.TreeSet;

public class A03_TreeSetDemo4 {
    public static void main(String[] args) {
        //创建集合
        TreeSet<Student2> ts = new TreeSet<>((o1,o2)->{
                //先按总分排
                int i=o1.getSum()-o2.getSum();
                //总分一样按语文排
                i=i==0?o1.getChinese()-o2.getChinese():i;
                //语文一样按数学排
                i=i==0?o1.getMath()-o2.getMath():i;
                //数学一样按英语排
                i=i==0?o1.getEngish()-o2.getEngish():i;
                //英语一样按年龄排
                i=i==0?o1.getAge()-o2.getAge():i;
                //年龄一样按姓名字母排
            i=i==0?o1.getName().compareTo(o2.getName()):i;
                //都一样，默认是同一个学生
                return i;
            }
        );

        //添加学生
        ts.add(new Student2("zhangsan",19,100,120,99));
        ts.add(new Student2("lisi",20,99,111,120));
        ts.add(new Student2("wangwu",18,111,111,99));
        ts.add(new Student2("zhaoliu",22,120,99,89));
        ts.add(new Student2("xiaoxixi",21,90,99,130));

        //System.out.println(ts);

        //打印
        for (Student2 stu : ts) {
            System.out.println(stu+" "+stu.getSum());
        }
    }
}
